---
layout: example
categories: example/v1.0.0
version: v1.0.0
title: Leaflet Draw
description: Add drawing tools for users to author shapes using the Leaflet Draw plugin.
tags:
  - plugins
---
<link href='{{site.tileApi}}/mapbox.js/plugins/leaflet-draw/v0.2.3/leaflet.draw.css' rel='stylesheet' />
<script src='{{site.tileApi}}/mapbox.js/plugins/leaflet-draw/v0.2.3/leaflet.draw.js'></script>

<div id='map'></div>

<script>
  var map = L.mapbox.map('map', 'mapbox.streets')
      .setView([38.89399, -77.03659], 17);

  var featureGroup = L.featureGroup().addTo(map);

  // Define circle options
  // http://leafletjs.com/reference.html#circle
  var circle_options = {
      color: '#fff',      // Stroke color
      opacity: 1,         // Stroke opacity
      weight: 10,         // Stroke weight
      fillColor: '#000',  // Fill color
      fillOpacity: 0.6    // Fill opacity
  };

  var circle_one = L.circle([38.89415, -77.03738], 20, circle_options).addTo(featureGroup);
  var circle_two = L.circle([38.89415, -77.03578], 20, circle_options).addTo(featureGroup);

  // Create array of lat,lon points
  var line_points = [
      [38.893596444352134, -77.0381498336792],
      [38.89337933372204, -77.03792452812195],
      [38.89316222242831, -77.03761339187622],
      [38.893028615148424, -77.03731298446655],
      [38.892920059048464, -77.03691601753235],
      [38.892903358095296, -77.03637957572937],
      [38.89301191422077, -77.03592896461487],
      [38.89316222242831, -77.03549981117249],
      [38.89340438498248, -77.03514575958252],
      [38.893596444352134, -77.0349633693695]
  ];

  // Define polyline options
  // http://leafletjs.com/reference.html#polyline
  var polyline_options = {
      color: '#000'
  };

  // Defining a polygon here instead of a polyline will connect the
  // endpoints and fill the path.
  // http://leafletjs.com/reference.html#polygon
  var polyline = L.polyline(line_points, polyline_options).addTo(featureGroup);

  var drawControl = new L.Control.Draw({
    edit: {
      featureGroup: featureGroup
    }
  }).addTo(map);

  map.on('draw:created', function(e) {
      featureGroup.addLayer(e.layer);
  });
</script>
